<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>DZI (Deep Zoom Image) Load</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Import maps polyfill -->
    <!-- Remove this when import maps will be widely supported -->
    <script async src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>

    <script type="importmap">
    {
        "imports": {
          "threepipe": "./../../dist/index.mjs",
          "@threepipe/plugin-3d-tiles-renderer": "./../../plugins/3d-tiles-renderer/dist/index.mjs"
        }
    }

    </script>
    <style id="example-style">
        html, body, #canvas-container, #mcanvas {
            width: 100%;
            height: 100%;
            margin: 0;
            overflow: hidden;
        }
    </style>
    <script type="module" src="../examples-utils/global-loading.mjs"></script>
    <script type="module" src="../examples-utils/simple-code-preview.mjs"></script>
    <script id="example-script" type="module" lang="ts">
        import {_testFinish, _testStart, LoadingScreenPlugin, ThreeViewer, SSAAPlugin} from 'threepipe'
        import {DeepZoomImageLoadPlugin, EnvironmentControlsPlugin} from '@threepipe/plugin-3d-tiles-renderer'

        const viewer = new ThreeViewer({canvas: document.getElementById('mcanvas'),
            msaa: true, renderScale: window.devicePixelRatio,
            tonemap: false})
        viewer.addPluginsSync([EnvironmentControlsPlugin, DeepZoomImageLoadPlugin, LoadingScreenPlugin, SSAAPlugin])

        async function init() {

            viewer.scene.mainCamera.position.set(0,0, 20)
            viewer.scene.mainCamera.lookAt(0,0, 0)
            viewer.scene.mainCamera.minNearPlane = 0.1
            viewer.scene.mainCamera.setDirty()
            viewer.scene.mainCamera.controlsMode = 'environment'
            viewer.scene.mainCamera.controls.minDistance = 0.3
            viewer.scene.mainCamera.controls.maxDistance = 50
            viewer.scene.mainCamera.controls.enableDamping = true
            viewer.scene.mainCamera.controls.cameraRadius = 0.25
            viewer.scene.mainCamera.controls.fallbackPlane.normal.set( 0,0 , 1 );
            viewer.scene.mainCamera.controls.up.set( 0, 0, 1 );

            // https://github.com/CesiumGS/3d-tiles-samples
            // from https://github.com/NASA-AMMOS/3DTilesRendererJS/blob/master/example/data/root.b3dm
            const result = await viewer.load('https://openseadragon.github.io/example-images/duomo/duomo.dzi', {
                autoCenter: true,
                autoScale: true,
                autoScaleRadius: 30,
                tiles: {
                    DeepZoomImagePlugin: {
                        center: true
                    },
                    errorTarget: 1,
                }
            })
            viewer.setDirty()
            console.log(result)
        }

        _testStart()
        init().finally(_testFinish)
    </script>
</head>
<body>
<div id="canvas-container">
    <canvas id="mcanvas"></canvas>
</div>

</body>
